﻿package com.tangrong.filesystem;

import java.util.ArrayList;
import java.util.List;

import com.tangrong.filesystem.observer.Observable;
import com.tangrong.filesystem.visitor.Visitor;

public class Directory extends File implements Observable {

	private List<File> files;
	
	public Directory(){
		super();
		if( null == this.files){
			this.files = new ArrayList<File>();
		}
	}
	
	public Directory(String name){
		super(name);
		if( null == this.files){
			this.files = new ArrayList<File>();
		}
	}
	
	
	@Override
	public void addFile(File node) {
		this.files.add(node);
	}

	@Override
	public void removeFile(File node) {
		this.files.remove(node);
	}

	@Override
	public void accept(Visitor v) {
		v.visit(this);
	}

	
	@Override
	public void notifyObservers() {
		logger.info("just delete directory: " + this.name);
		for(Link l : this.links){
			l.update(this, "Directory " + this.name + "removed");
		}
	}
	
	@Override
	public void notifyObservers(Object obj) {
		this.notifyObservers();
	}

	@Override
	public void doSomething() {
		this.notifyObservers();
	}

}
